home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Nested Template Classes
- Date: 06 Feb 1996 17:02:58 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Feb6180259@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4f6kql$70s@charnel.ecst.csuchico.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: mcelroy@ecst.csuchico.edu's message of 6 Feb 1996 04:18:29 GMT
-
- In article <4f6kql$70s@charnel.ecst.csuchico.edu> mcelroy@ecst.csuchico.edu (James Robert McElroy) writes:
-
- Here's a real brain-twister for you, something hiding
- off in the dark recesses of C++dom.
-
- What does the function definition for a nested template
- class function look like? IS there such a construct? I have
- not been able to find one that works (except for inlining
- every nested template class function).
-
- e.g. Normal:
-
- class list {
- private:
- class node {
- private:
- int data;
- node * next;
- public:
- node(int someData);
- int getData();
- etc...
- };
- public:
- whatever...
-
- };
-
- int list::node::getData() { return data; } // okay -- correct form
-
-
- Templated: take the above class definition and templatize
- it, replacing the type of node::data with the
- template parameter "T" instead of "int".
-
- Now, assuming you don't want to inline the
- getData method, how do you define it?
-
- template <class T>
- T list<T>::node<T>::getData() { return data; } // doesn't work
-
- template <class T>
- T list<T>::node::getData() { return data; } // doesn't work
-
- template <class T>
- T list::node<T>::getData() { return data; } // doesn't work
-
- template <class T>
- T list::node::getData() { return data; } // doesn't work,
- of course.
-
-
- The compiler barfs on all of these.
-
- The 2nd solution is correct.
-
- Enno
-